package com.liang.publics.ui

import android.content.Context
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView


import com.lxj.xpopup.core.CenterPopupView
import com.liang.publics.ad.ads.AsService

import com.liang.publics.util.SharedPreferencesUtil
import com.liang.maogouyuyin.R


class RTExitDialogPopup(context: Context) : CenterPopupView(context){
    var listener: OnExitClickListener? = null

//   lateinit var  adservice:AsService;

    override fun getImplLayoutId(): Int {
        return R.layout.public_popup_exit_dialog
    }

    lateinit var feed_container_exit_dialog:FrameLayout

    override fun onCreate() {
        super.onCreate()
        var  adservice: AsService   = AsService();
        var exit_tv_cancel = findViewById<ImageView>(R.id.exit_tv_cancel)
        var exit_tv_cancel1 = findViewById<TextView>(R.id.exit_tv_cancel1)
        var exit_tv_check = findViewById<TextView>(R.id.exit_tv_check)
        var money_tv_zuanqian = findViewById<TextView>(R.id.money_tv_zuanqian)
//        if (!WidgetsUtils.isExistAppWidget(context)) {
//            money_tv_zuanqian.text="重要功能修复后可延长手机寿命"
//            exit_tv_check.text="立即修复"
//        }else{
//            money_tv_zuanqian.text="当前网络可提速17%"
//            exit_tv_check.text="立即提速"
//        }
        feed_container_exit_dialog = findViewById<FrameLayout>(R.id.feed_container_exit_dialog)
        exit_tv_cancel.setOnClickListener {//X
            adservice.showAd("full", activity)
            dismiss()
            listener?.closeDialog()
        }
        exit_tv_cancel1.setOnClickListener {//取消
            listener?.cancel()
            activity.finish()

        }

        exit_tv_check.setOnClickListener {//确认
            adservice.showAd("full", activity)
            dismiss()
            listener?.ok()
        }

        if (SharedPreferencesUtil.getStatus(SharedPreferencesUtil.IF_AD)) {

              adservice = AsService()
            adservice.initAd("feed", context, resources.getString(R.string.feed_native_media_id),feed_container_exit_dialog);

            //信息
            adservice.showAd("feed", activity)
//            //激励
//            initAd("reward", context,null)
            adservice.initAd("full", context,resources.getString(R.string.full_media_2_id),null)
//            //插屏

//
//
//                if (Const.shuangInterstitialFull) {
//                    initAd("full2", context)
//                    showAd("full2", activity)
//                }

        }


    }





    override fun onShow() {
        super.onShow()
    }



    override fun onDismiss() {

        super.onDismiss()

    }



    interface OnExitClickListener {
        fun cancel()
        fun closeDialog()
        fun ok()
    }
}